<?php
/**
 * Created by PhpStorm.
 * User: ls721
 * Date: 2016/10/23 0023
 * Time: 21:39
 */class Model_Comment extends PhalApi_Model_NotORM {
    public function isExist($event_id,$doctor_id)
    {
      return  $this->getORM()->select('*')
            ->where('Event_id',$event_id)
            ->where('Doctor_id',$doctor_id)
            ->fetch();
    }
    public function listComment($doctor_id, $event_id)
    {
        $comment = $this->getORM();
        $comment->select(
            'Comment.id as CommentId',
            'Event_id as EventId',
            'Doctor_id as DoctorId',
            'Event.Location as Location',
            'Event.Title as Title',
            'Comment.CreateDate');
        if (!empty($doctor_id)) {
            $comment->where('Doctor_id', $doctor_id);
        }
        if (!empty($event_id)) {
            $comment->where('Event_id', $event_id);
        }

        return $comment->fetchRows();
    }
    public function listRecord( $event_id)
    {
        $comment = $this->getORM();
        $comment->select(

            'Comment.CreateDate',
            'Comment.Record',
            'Doctor.Name as Name'

        );
//        if (!empty($doctor_id)) {
//            $comment->where('Doctor_id', $doctor_id);
//        }
        if (!empty($event_id)) {
            $comment->where('Event_id', $event_id);
        }

        return $comment->fetchRows();
    }

    public function getComment($comment_id)
    {
        return $this->getORM()->select(
            'Comment.id as CommentId',
            'Event_id as EventId',
            'Doctor_id as DoctorId',
            'Doctor.Name as DoctorName',
            'Comment.Content',
            'Comment.CreateDate',
            'Comment.Record'
        )
            ->where('Comment.id', $comment_id)
            ->fetch();
    }

    protected function getTableName($id) {
        return 'Comment';
    }
}